﻿using HBFramework;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Panel_Mask : BasePanel
{
    public override int RemainTime => PanelRemainTime.Permanent;

    public override int Layer => PanelLayer.Mask;

    public override string Path => "ui/panel_mask";

    private static List<int> maskIds;
    private static Button btn_mask;

    public override void OnInit(GameObject ui)
    {
        btn_mask = ui.transform.Find("btn_mask").GetComponent<Button>();
        btn_mask.onClick.AddListener(OnMaskBtnClick);
        btn_mask.gameObject.SetActive(false);
    }

    public override void OnRelease()
    {
        btn_mask.onClick.RemoveListener(OnMaskBtnClick);
    }

    private void OnMaskBtnClick()
    {
        var str = "maskIds: ";
        for (int i = 0; i < maskIds.Count; i++)
        {
            str += maskIds[i] + ",";
        }
        Debug.Log(str);
    }

    /// <summary>
    /// 展示遮罩
    /// </summary>
    /// <param name="id"></param>
    /// <param name="clear"></param>
    public static void ShowMask(int id, bool clear = true)
    {
        maskIds ??= new List<int>();
        if (clear)
        {
            maskIds.Clear();
        }
        maskIds.Add(id);
        btn_mask.gameObject.SetActive(true);
    }

    /// <summary>
    /// 隐藏遮罩
    /// </summary>
    /// <param name="id"></param>
    /// <param name="force"></param>
    public static void HideMask(int id, bool force = false)
    {
        if (force)
        {
            btn_mask.gameObject.SetActive(false);
        }
        else
        {
            if (maskIds != null
                && maskIds.Contains(id))
            {
                maskIds.Remove(id);
            }
            if (maskIds == null
                || maskIds.Count <= 0)
            {
                btn_mask.gameObject.SetActive(false);
            }
        }
    }
}
